//
//  UIImageView+SCwebImage.m
//  Shuaiche
//
//  Created by dangshuai on 2018/12/18.
//  Copyright © 2018 zzs. All rights reserved.
//

#import "UIImageView+SCwebImage.h"
#import <UIImageView+WebCache.h>
@implementation UIImageView (SCwebImage)
- (void)sc_setImageWithPath:(NSString *)path {
    [self sc_setImageWithPath:path withPlaceHolder:nil];
}

- (void)sc_setImageWithPath:(NSString *)path withPlaceHolder:(NSString *)placeHolder {
    NSString *url = sc_url_img(path);
//    [self sc_setimageWithUrl:url withPlaceHolder:placeHolder];
    if (placeHolder.length) {
        [self sd_setImageWithURL:[NSURL URLWithString:url] placeholderImage:[UIImage imageNamed:placeHolder]];
    } else {
        [self sd_setImageWithURL:[NSURL URLWithString:url]];
    }
}

- (void)sc_setimageWithUrl:(NSString *)url withPlaceHolder:(NSString *)placeholder {
    if (placeholder.length) {
        [self sd_setImageWithURL:[NSURL URLWithString:url] placeholderImage:[UIImage imageNamed:placeholder]];
    } else {
        [self sd_setImageWithURL:[NSURL URLWithString:url]];
    }
}

- (void)sc_setSamllImageWithUrlString:(NSString *)urlString withPlaceHolder:(NSString *)placeholder {
    if ([urlString containsString:@"?x-oss-process=style/"]) {
        NSRange range = [urlString rangeOfString:@"?"];
        if (range.location != NSNotFound) {
            urlString = [urlString substringToIndex:range.location];
        }
    }
    [self sc_setimageWithUrl:API_IMAGE_PROCESS_URL(urlString,API_IMAGE_LIST_TYPE) withPlaceHolder:placeholder];
}

- (void)sc_set780ImageWithUrlString:(NSString *)urlString withPlaceHolder:(NSString *)placeholder {
    if ([urlString containsString:@"?x-oss-process=style/"]) {
        NSRange range = [urlString rangeOfString:@"?"];
        if (range.location != NSNotFound) {
            urlString = [urlString substringToIndex:range.location];
        }
    }
    [self sc_setimageWithUrl:API_IMAGE_PROCESS_URL(urlString,API_IMAGE_780_TYPE) withPlaceHolder:placeholder];
}


- (void)sc_cancelImageLoad {
//    [self sd_cancelCurrentImageLoad];
}

@end
